<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Dataanalysis_Controller
 *
 * @author Dragon.hu
 */
defined('BASEPATH') or die('forbidden');
 
class Dataanalysis_Controller extends Controller
{
	private $baseurl = "http://log.reyun.com";
	private $appid = "632aba087a35cf0112bc79cc5ff795fb"; //数据分析平台的appid
	
	private $objectList;
	private $taskList;
	private $productidList;
	function _init()
	{
		$this->inc = $this->config['inc'];
		$this->wholeServerHost = $this->config['host_url'];
		
		$this->objectList = get_type_object_id_name();
		$this->taskList = get_type_task();
		
		$this->productidList = array(
				"1"=>"30元月卡充值 ",
				"2"=>"198元十年卡充值 ",
				"3"=>"10元钻石卡充值 ",
				"4"=>"30元钻石卡充值 ",
				"5"=>"50元钻石卡充值 ",
				"6"=>"100元钻石卡充值 ",
				"7"=>"200元钻石卡充值 ",
				"8"=>"300元钻石卡充值 ",
				"9"=>"1000元钻石卡充值 "
		);
		
		$config = get_config();
		if ($config['reyun_switch'] == 1)
		{
			$this->baseurl = "http://log.reyun.com";
		}
		else
		{
			$this->baseurl = "";
		}
	}
	
	/*function datapost($url, $data_string) {
	
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json; charset=utf-8',
		'Content-Length: ' . strlen($data_string))
		);
		ob_start();
		curl_exec($ch);
		$return_content = ob_get_contents();
		ob_end_clean();
	
		$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		return array($return_code, $return_content);
	}*/
	
	function installData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['context']['deviceid'] = $row['deviceid'];
		$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/install";
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function startupData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['context']['deviceid'] = $row['deviceid'];
		$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/startup";
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function registerData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['who'] = $row['who'];
		$data['context']['deviceid'] = $row['deviceid'];
		$data['context']['serverid'] = $row['serverid'];
		$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/register";
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function loggedinData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['who'] = $row['who'];
		$data['context']['deviceid'] = $row['deviceid'];
		$data['context']['serverid'] = $row['serverid'];
		$data['context']['level'] = $row['level'];
		$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/loggedin";
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function paymentData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['context']['deviceid'] = $row['deviceid'];
		$data['context']['transactionid'] = $row['transactionid'];
		$data['context']['paymenttype'] = $row['paymenttype'];
		$data['context']['currencytype'] = $row['currencytype'];
		$data['context']['currencyamount'] = $row['currencyamount'];
		$data['context']['virtualcoinamount'] = $row['virtualcoinamount'];
		
		$tmpname = $this->productidList[$row['iapname']]."(".$row['iapname'].")";
		$data['context']['iapname'] = $tmpname;
		
		$data['context']['iapamount'] = $row['iapamount'];
		$data['context']['serverid'] = $row['serverid'];
		$data['context']['level'] = $row['level'];
		//$data['context']['channelid'] = $row['channelid'];
		$data['who'] = $row['who'];
		
		//转成为可发送的json格式
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/payment";
		//print_r($this->baseurl);
		//print_r("+=+=+");
		//print_r($url);
		//print_r("+++++");
		//print_r($data);
		//print_r("=====");
		//print_r($datajson);
		//exit(0);
		list($return_code, $return_content) = datapost($url,$datajson);
		//print_r($return_content);
		//print_r("++++");
		$ret = json_decode($return_content, true);
		//print_r($ret);
		//exit(0);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function economyData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['who'] = $row['who'];
		$data['context']['deviceid'] = $row['deviceid'];
		
		$tmpname = $this->objectList[$row['itemname']]."-".$row['itemname'];
		$data['context']['itemname'] = $tmpname;
		
		$data['context']['itemamount'] = $row['itemamount'];
		$data['context']['itemtotalprice'] = $row['itemtotalprice'];
		$data['context']['serverid'] = $row['serverid'];
		$data['context']['level'] = $row['level'];
		//$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/economy";
		//print_r($data);
		//exit(0);
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function questData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['who'] = $row['who'];
		$data['context']['deviceid'] = $row['deviceid'];
		
		$tmpname = $this->taskList[$row['questId']]."-".$row['questId'];
		$data['context']['questId'] = $tmpname;
		
		$data['context']['queststatus'] = $row['queststatus'];
		$data['context']['questtype'] = $row['questtype'];
		$data['context']['serverid'] = $row['serverid'];
		$data['context']['level'] = $row['level'];
		//$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/quest";
		//print_r($data);
		//exit(0);
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function eventData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		//待添加
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/event";
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
	
	function heartbeatData()
	{
		$row = $_GET;
		$data = array();
		$data['appid'] = $this->appid;
		$data['who'] = $row['who'];
		$data['context']['deviceid'] = $row['deviceid'];
		$data['context']['serverid'] = $row['serverid'];
		$data['context']['level'] = $row['level'];
		$data['context']['channelid'] = $row['channelid'];
		
		$datajson = json_encode($data);
		$url = $this->baseurl."/receive/rest/heartbeat";
		
		list($return_code, $return_content) = datapost($url,$datajson);
		$ret = json_decode($return_content, true);
		if ($ret['status'] == 0)
		{
			echo "ret=success";
		}else{
			echo "ret=fail";
		}
	}
}





?>